﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for ConnectOracle
/// </summary>
public class ConnectOracle
{
    static public DataTable GetTab(string sql, string company)
    {
        Oracle.Oracle oracle = new Oracle.Oracle();
        oracle.Url = System.Configuration.ConfigurationManager.AppSettings["OracleServer"];

        string[] par = { sql, "DBPENANSHIN", "SCCPENADM", "SCCPENADM" };
        if (company == "01" || company.ToUpper().IndexOf("INTERNATIONAL") != -1)
        {
            oracle.Url = System.Configuration.ConfigurationManager.AppSettings["OracleServer_Mp"];
            par = new string[] { sql, "MPIF", "ADMIN", "PASSWORD" };
        }
        else if (company == "02" || company.ToLower().IndexOf("consol") != -1)
        {
            oracle.Url = System.Configuration.ConfigurationManager.AppSettings["OracleServer_Mp"];
            par = new string[] { sql, "MPIF2", "ADMIN", "PASSWORD" };
        }
        DataTable master = oracle.List("shipmentnetwork", par);

        return master;
    }
    static public DataSet GetDataSet(string[] sqls, string company)
    {
        Oracle.Oracle oracle = new Oracle.Oracle();
        oracle.Url = System.Configuration.ConfigurationManager.AppSettings["OracleServer"];
        DataSet set = new DataSet("set");
        for (int i = 0; i < sqls.Length; i++)
        {
            string sql = sqls[i];
            string[] par = { sql, "DBPENANSHIN", "SCCPENADM", "SCCPENADM" };
            if (company == "01" || company.ToUpper().IndexOf("INTERNATIONAL") != -1)
            {
                oracle.Url = System.Configuration.ConfigurationManager.AppSettings["OracleServer_Mp"];
                par = new string[] { sql, "MPIF", "ADMIN", "PASSWORD" };
            }
            else if (company == "02" || company.ToLower().IndexOf("consol") != -1)
            {
                oracle.Url = System.Configuration.ConfigurationManager.AppSettings["OracleServer_Mp"];
                par = new string[] { sql, "MPIF2", "ADMIN", "PASSWORD" };
            }
            DataTable tab = oracle.List("shipmentnetwork", par);
            tab.TableName = "Name" + i.ToString();
            set.Tables.Add(tab);
        }
        return set;
    }
    static public int ExecuteSql(string sql, string company)
    {
        Oracle.Oracle oracle = new Oracle.Oracle();
        oracle.Url = System.Configuration.ConfigurationManager.AppSettings["OracleServer"];
        string[] par = { sql, "DBPENANSHIN", "SCCPENADM", "SCCPENADM" };
        //if (company.ToUpper() != "PENANSHIN" && company != "00")
        //    par = new string[] { sql, "MPIF", "ADMIN", "PASSWORD" };
        int flag = oracle.Update("shipmentnetwork", par);
        return flag;
    }



    static public DataTable GetDbTpTab(string sql)
    {
        try
        {
            Oracle.Oracle oracle = new Oracle.Oracle();
            oracle.Url = System.Configuration.ConfigurationManager.AppSettings["OracleServer"];
           //  string[] par = { sql, "ORCL", "SCCDMS", "SCCDMS" };
           string[] par = { sql, "DBTP", "ADMIN", "PASSWORD" };
            DataTable master = oracle.List("shipmentnetwork", par);
            oracle.Dispose();
            return master;
        }
        catch { }
        return new DataTable();
    }
    static public object GetDbTpObject(string sql)
    {
        try
        {
            Oracle.Oracle oracle = new Oracle.Oracle();
            oracle.Url = System.Configuration.ConfigurationManager.AppSettings["OracleServer"];
            //string[] par = { sql, "ORCL", "SCCDMS", "SCCDMS" };
            string[] par = { sql, "DBTP", "ADMIN", "PASSWORD" };
            DataTable master = oracle.List("shipmentnetwork", par);
            oracle.Dispose();
            if (master.Rows.Count == 1)
                return master.Rows[0][0];
        }
        catch { }
        return null;
    }
    static public int ExecuteDbTpSql(string sql)
    {
        try
        {
            Oracle.Oracle oracle = new Oracle.Oracle();
            oracle.Url = System.Configuration.ConfigurationManager.AppSettings["OracleServer"];
            //string[] par = { sql, "ORCL", "SCCDMS", "SCCDMS" };
            string[] par = { sql, "DBTP", "ADMIN", "PASSWORD" };
            int flag = oracle.Update("shipmentnetwork", par);
            oracle.Dispose();

            return flag;
        }
        catch { }
        return 0;
    }
}

